package fr.babostesting.examples.mobile.bench 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import fr.babos.core.entries.Document;
	import net.hires.debug.Stats;
	
	/**
	 * Bench sur les perfs des bitmaps en mode GPU
	 * @author ZoulouX
	 */
	public class BitmapBench extends Document
	{
		private var _bitmapData:BitmapData;
		private var _bitmap:Bitmap;
		public function BitmapBench ()
		{
			
		}
		
		override public function init ():void
		{
			_bitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
			_bitmap = new Bitmap(_bitmapData, PixelSnapping.NEVER, false);
			
			_bitmap.width = stage.stageWidth;
			_bitmap.height = stage.stageHeight;
			
			stage.quality = StageQuality.LOW;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			stage.autoOrients = false;
			
			addChild(_bitmap);
			addChild(new Stats());
			
			stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		protected var _increment:int;
		
		protected function enterFrameHandler (event:Event):void
		{
			_bitmapData.lock();
			
			_bitmapData.scroll(0, 1);
			
			_increment = stage.stageWidth;
			while (-- _increment > 0)
			{
				_bitmapData.setPixel(_increment, 1, 0xFF * Math.random());
			}
			
			
			_bitmapData.unlock();
		}
	}
}